//
//  AppDelegate.m
//  SIqICalendar
//
//  Created by SKiran on 16/5/20.
//  Copyright © 2016年 sjw. All rights reserved.
//

#import "AppDelegate.h"
#import "ZXNavigationController.h"
#import "JWCalendarListController.h"
#import "UMMobClick/MobClick.h"
#import "JWCalendarModel.h"
#import "JWRootSideMenuViewController.h"
#import "JWCalendarsScheduleViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [self umengTrack];
    
    // 全局改变Nav
    [self changeNav];
    
    RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
    config.schemaVersion = 11;
    config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion)
    {    // enumerateObjects:block: 遍历了存储在 Realm 文件中的每一个“Person”对象
        [migration enumerateObjects:JWCalendarModel.className block:^(RLMObject *oldObject, RLMObject *newObject) {
            
        }];
    };
    
    [RLMRealmConfiguration setDefaultConfiguration:config];// 现在我们已经成功更新

    ZXNavigationController *nav = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"JWCalendarRootNavigationController"];
    
    JWCalendarListController *left = [[JWCalendarListController alloc]initWithNibName:NSStringFromClass([JWCalendarListController class]) bundle:nil];
    

    JWCalendarsScheduleViewController *right = [[JWCalendarsScheduleViewController alloc]initWithNibName:NSStringFromClass([JWCalendarsScheduleViewController class]) bundle:nil];
    UINavigationController *rightNav = [[UINavigationController alloc]initWithRootViewController:right];
    JWRootSideMenuViewController *root = [[JWRootSideMenuViewController alloc]initWithRootViewController:nav leftViewController:left rightViewController:rightNav];
    
    self.window.rootViewController = root;
    [self.window makeKeyAndVisible];
    
    return YES;
}


- (void)umengTrack {
    [MobClick setAppVersion:XcodeAppVersion]; //参数为NSString * 类型,自定义app版本信息，如果不设置，默认从CFBundleVersion里取
    [MobClick setLogEnabled:YES];
    UMConfigInstance.appKey = @"58d4b657f43e480d31000449";
    [MobClick startWithConfigure:UMConfigInstance];
}


/**
 *  全局改变Nav
 */

- (void)changeNav
{
    //设置NavigationBar背景颜色
    [[UINavigationBar appearance] setBarTintColor:NavigationBarTintColor];
    
    //@{}代表Dictionary
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:TitleColor}];
    //不设置这个无法修改状态栏字体颜色
    [[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
    
    //返回按钮的颜色
    [[UINavigationBar appearance] setTintColor:TitleColor];
    
//    //返回按钮去掉返回页的文字
//    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
//                                                         forBarMetrics:UIBarMetricsDefault];
    
    
}


- (void)applicationWillResignActive:(UIApplication *)application {
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
